home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / !Interfaces / Universal Interfaces 2.0a1 / CIncludes / Power.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-17  |  13.8 KB  |  486 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        Power.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a1.  ETO #15, MPW prerelease.  Sunday, July 17, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __POWER__
  18. #define __POWER__
  19.  
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24. /*    #include <ConditionalMacros.h>                                */
  25.  
  26. #ifndef __MIXEDMODE__
  27. #include <MixedMode.h>
  28. #endif
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. #if GENERATINGPOWERPC
  35. #pragma options align=mac68k
  36. #endif
  37.  
  38. #ifdef __CFM68K__
  39. #pragma lib_export on
  40. #endif
  41.  
  42.  
  43. enum {
  44. /* Bit positions for ModemByte */
  45.     modemOnBit                    = 0,
  46.     ringWakeUpBit                = 2,
  47.     modemInstalledBit            = 3,
  48.     ringDetectBit                = 4,
  49.     modemOnHookBit                = 5,
  50. /* masks for ModemByte */
  51.     modemOnMask                    = 0x1,
  52.     ringWakeUpMask                = 0x4,
  53.     modemInstalledMask            = 0x8,
  54.     ringDetectMask                = 0x10,
  55.     modemOnHookMask                = 0x20,
  56. /* bit positions for BatteryByte */
  57.     chargerConnBit                = 0,
  58.     hiChargeBit                    = 1,
  59.     chargeOverFlowBit            = 2,
  60.     batteryDeadBit                = 3,
  61.     batteryLowBit                = 4,
  62.     connChangedBit                = 5,
  63. /* masks for BatteryByte */
  64.     chargerConnMask                = 0x1,
  65.     hiChargeMask                = 0x2,
  66.     chargeOverFlowMask            = 0x4,
  67.     batteryDeadMask                = 0x8
  68. };
  69.  
  70. enum {
  71.     batteryLowMask                = 0x10,
  72.     connChangedMask                = 0x20,
  73. /* commands to SleepQRec sleepQProc */
  74.     sleepRequest                = 1,
  75.     sleepDemand                    = 2,
  76.     sleepWakeUp                    = 3,
  77.     sleepRevoke                    = 4,
  78. /* SleepQRec.sleepQFlags */
  79.     noCalls                        = 1,
  80.     noRequest                    = 2,
  81.     slpQType                    = 16,
  82.     sleepQType                    = 16
  83. };
  84.  
  85. /* bits in bitfield returned by PMFeatures */
  86. enum {
  87.     hasWakeupTimer                = 0,                            /* 1=wakeup timer is supported                        */
  88.     hasSharedModemPort            = 1,                            /* 1=modem port shared by SCC and internal modem    */
  89.     hasProcessorCycling            = 2,                            /* 1=processor cycling is supported                    */
  90.     mustProcessorCycle            = 3,                            /* 1=processor cycling should not be turned off        */
  91.     hasReducedSpeed                = 4,                            /* 1=processor can be started up at reduced speed    */
  92.     dynamicSpeedChange            = 5,                            /* 1=processor speed can be switched dynamically    */
  93.     hasSCSIDiskMode                = 6,                            /* 1=SCSI Disk Mode is supported                    */
  94.     canGetBatteryTime            = 7,                            /* 1=battery time can be calculated                    */
  95.     canWakeupOnRing                = 8,                            /* 1=can wakeup when the modem detects a ring        */
  96.     hasDimmingSupport            = 9                                /* 1 has dimming support built into the rom            */
  97. };
  98.  
  99. /* bits in bitfield returned by GetIntModemInfo and set by SetIntModemState */
  100. enum {
  101.     hasInternalModem            = 0,                            /* 1=internal modem installed                        */
  102.     intModemRingDetect            = 1,                            /* 1=internal modem has detected a ring                */
  103.     intModemOffHook                = 2,                            /* 1=internal modem is off hook                        */
  104.     intModemRingWakeEnb            = 3,                            /* 1=wakeup on ring is enabled                        */
  105.     extModemSelected            = 4,                            /* 1=external modem selected                        */
  106.     modemSetBit                    = 15                            /* 1=set bit, 0=clear bit (SetIntModemState)        */
  107. };
  108.  
  109. /* bits in BatteryInfo.flags                                     */
  110. /* ("chargerConnected" doesn't mean the charger is plugged in)    */
  111. enum {
  112.     batteryInstalled            = 7,                            /* 1=battery is currently connected                    */
  113.     batteryCharging                = 6,                            /* 1=battery is being charged                        */
  114.     chargerConnected            = 5                                /* 1=charger is connected to the PowerBook            */
  115. };
  116.  
  117. enum {
  118.     HDPwrQType                    = 'HD'
  119. };
  120.  
  121. /* information returned by GetScaledBatteryInfo */
  122. typedef struct BatteryInfo BatteryInfo;
  123.  
  124. struct BatteryInfo {
  125.     UInt8                            flags;                        /* misc flags (see below)                            */
  126.     UInt8                            warningLevel;                /* scaled warning level (0-255)                        */
  127.     UInt8                            reserved;                    /* reserved for internal use                        */
  128.     UInt8                            batteryLevel;                /* scaled battery level (0-255)                        */
  129. };
  130. typedef SInt8 ModemByte;
  131.  
  132. typedef SInt8 BatteryByte;
  133.  
  134. typedef long PMResultCode;
  135.  
  136. typedef struct SleepQRec SleepQRec, *SleepQRecPtr;
  137.  
  138. typedef struct HDQueueElement HDQueueElement;
  139.  
  140. typedef pascal void (*HDSpindownProcPtr)(HDQueueElement *theElement);
  141. /*
  142.         SleepQProcPtr uses register based parameters on the 68k and cannot
  143.         be written in or called from a high-level language without the help of
  144.         mixed mode or assembly glue.
  145.  
  146.         In:
  147.          => message         D0.L
  148.          => qRecPtr         A0.L
  149.         Out:
  150.          <= return value    D0.L
  151. */
  152.  
  153. #if GENERATINGCFM
  154. typedef UniversalProcPtr HDSpindownUPP;
  155. typedef UniversalProcPtr SleepQUPP;
  156. #else
  157. typedef HDSpindownProcPtr HDSpindownUPP;
  158. typedef Register68kProcPtr SleepQUPP;
  159. #endif
  160.  
  161. struct HDQueueElement {
  162.     Ptr                                hdQLink;                    /* pointer to next queue element                    */
  163.     short                            hdQType;                    /* queue element type (must be HDQType)                */
  164.     short                            hdFlags;                    /* miscellaneous flags                                */
  165.     HDSpindownUPP                    hdProc;                        /* pointer to routine to call                        */
  166.     long                            hdUser;                        /* user-defined (variable storage, etc.)            */
  167. };
  168. struct SleepQRec {
  169.     struct SleepQRec                *sleepQLink;
  170.     short                            sleepQType;                    /* type = 16                            */
  171.     SleepQUPP                        sleepQProc;                    /* Pointer to sleep universal proc ptr    */
  172.     short                            sleepQFlags;
  173. };
  174. /* wakeup time record */
  175. typedef struct WakeupTime WakeupTime;
  176.  
  177. struct WakeupTime {
  178.     unsigned long                    wakeTime;                    /* wakeup time (same format as current time)        */
  179.     Boolean                            wakeEnabled;                /* 1=enable wakeup timer, 0=disable wakeup timer    */
  180.     SInt8                            filler;
  181. };
  182. /* battery time information (in seconds) */
  183. typedef struct BatteryTimeRec BatteryTimeRec;
  184.  
  185. struct BatteryTimeRec {
  186.     unsigned long                    expectedBatteryTime;        /* estimated battery time remaining                */
  187.     unsigned long                    minimumBatteryTime;            /* minimum battery time remaining                */
  188.     unsigned long                    maximumBatteryTime;            /* maximum battery time remaining                */
  189.     unsigned long                    timeUntilCharged;            /* time until battery is fully charged            */
  190. };
  191. extern pascal OSErr DisableWUTime(void);
  192. extern pascal OSErr SetWUTime(long WUTime);
  193. extern pascal OSErr GetWUTime(long *WUTime, Byte *WUFlag);
  194. extern pascal OSErr BatteryStatus(Byte *Status, Byte *Power);
  195. extern pascal OSErr ModemStatus(Byte *Status);
  196.  
  197. #if !GENERATINGCFM
  198. #pragma parameter __D0 IdleUpdate
  199. #endif
  200. extern pascal long IdleUpdate(void)
  201.  ONEWORDINLINE(0xA285);
  202.  
  203. #if !GENERATINGCFM
  204. #pragma parameter __D0 GetCPUSpeed
  205. #endif
  206. extern pascal long GetCPUSpeed(void)
  207.  TWOWORDINLINE(0x70FF, 0xA485);
  208. extern pascal void EnableIdle(void)
  209.  TWOWORDINLINE(0x7000, 0xA485);
  210. extern pascal void DisableIdle(void)
  211.  TWOWORDINLINE(0x7001, 0xA485);
  212.  
  213. #if !GENERATINGCFM
  214. #pragma parameter SleepQInstall(__A0)
  215. #endif
  216. extern pascal void SleepQInstall(SleepQRecPtr qRecPtr)
  217.  ONEWORDINLINE(0xA28A);
  218.  
  219. #if !GENERATINGCFM
  220. #pragma parameter SleepQRemove(__A0)
  221. #endif
  222. extern pascal void SleepQRemove(SleepQRecPtr qRecPtr)
  223.  ONEWORDINLINE(0xA48A);
  224. extern pascal void AOn(void)
  225.  TWOWORDINLINE(0x7004, 0xA685);
  226. extern pascal void AOnIgnoreModem(void)
  227.  TWOWORDINLINE(0x7005, 0xA685);
  228. extern pascal void BOn(void)
  229.  TWOWORDINLINE(0x7000, 0xA685);
  230. extern pascal void AOff(void)
  231.  TWOWORDINLINE(0x7084, 0xA685);
  232. extern pascal void BOff(void)
  233.  TWOWORDINLINE(0x7080, 0xA685);
  234. /* Newer PowerMgr functions */
  235.  
  236. #if !GENERATINGCFM
  237. #pragma parameter __D0 PMSelectorCount
  238. #endif
  239. extern pascal short PMSelectorCount(void)
  240.  TWOWORDINLINE(0x7000, 0xA09E);
  241.  
  242. #if !GENERATINGCFM
  243. #pragma parameter __D0 PMFeatures
  244. #endif
  245. extern pascal unsigned long PMFeatures(void)
  246.  TWOWORDINLINE(0x7001, 0xA09E);
  247.  
  248. #if !GENERATINGCFM
  249. #pragma parameter __D0 GetSleepTimeout
  250. #endif
  251. extern pascal UInt8 GetSleepTimeout(void)
  252.  TWOWORDINLINE(0x7002, 0xA09E);
  253.  
  254. #if !GENERATINGCFM
  255. #pragma parameter SetSleepTimeout(__D0)
  256. #endif
  257. extern pascal void SetSleepTimeout(UInt8 timeout)
  258.  FOURWORDINLINE(0x4840, 0x303C, 0x0003, 0xA09E);
  259.  
  260. #if !GENERATINGCFM
  261. #pragma parameter __D0 GetHardDiskTimeout
  262. #endif
  263. extern pascal UInt8 GetHardDiskTimeout(void)
  264.  TWOWORDINLINE(0x7004, 0xA09E);
  265.  
  266. #if !GENERATINGCFM
  267. #pragma parameter SetHardDiskTimeout(__D0)
  268. #endif
  269. extern pascal void SetHardDiskTimeout(UInt8 timeout)
  270.  FOURWORDINLINE(0x4840, 0x303C, 0x0005, 0xA09E);
  271.  
  272. #if !GENERATINGCFM
  273. #pragma parameter __D0 HardDiskPowered
  274. #endif
  275. extern pascal Boolean HardDiskPowered(void)
  276.  TWOWORDINLINE(0x7006, 0xA09E);
  277.  
  278. #if !GENERATINGCFM
  279. #pragma parameter SpinDownHardDisk
  280. #endif
  281. extern pascal void SpinDownHardDisk(void)
  282.  TWOWORDINLINE(0x7007, 0xA09E);
  283.  
  284. #if !GENERATINGCFM
  285. #pragma parameter __D0 IsSpindownDisabled
  286. #endif
  287. extern pascal Boolean IsSpindownDisabled(void)
  288.  TWOWORDINLINE(0x7008, 0xA09E);
  289.  
  290. #if !GENERATINGCFM
  291. #pragma parameter SetSpindownDisable(__D0)
  292. #endif
  293. extern pascal void SetSpindownDisable(Boolean setDisable)
  294.  FOURWORDINLINE(0x4840, 0x303C, 0x0009, 0xA09E);
  295.  
  296. #if !GENERATINGCFM
  297. #pragma parameter __D0 HardDiskQInstall(__A0)
  298. #endif
  299. extern pascal OSErr HardDiskQInstall(HDQueueElement *theElement)
  300.  TWOWORDINLINE(0x700A, 0xA09E);
  301.  
  302. #if !GENERATINGCFM
  303. #pragma parameter __D0 HardDiskQRemove(__A0)
  304. #endif
  305. extern pascal OSErr HardDiskQRemove(HDQueueElement *theElement)
  306.  TWOWORDINLINE(0x700B, 0xA09E);
  307.  
  308. #if !GENERATINGCFM
  309. #pragma parameter GetScaledBatteryInfo(__D0, __A0)
  310. #endif
  311. extern pascal void GetScaledBatteryInfo(short whichBattery, BatteryInfo *theInfo)
  312.  FIVEWORDINLINE(0x4840, 0x303C, 0x000C, 0xA09E, 0x2080);
  313.  
  314. #if !GENERATINGCFM
  315. #pragma parameter AutoSleepControl(__D0)
  316. #endif
  317. extern pascal void AutoSleepControl(Boolean enableSleep)
  318.  FOURWORDINLINE(0x4840, 0x303C, 0x000D, 0xA09E);
  319.  
  320. #if !GENERATINGCFM
  321. #pragma parameter __D0 GetIntModemInfo
  322. #endif
  323. extern pascal unsigned long GetIntModemInfo(void)
  324.  TWOWORDINLINE(0x700E, 0xA09E);
  325.  
  326. #if !GENERATINGCFM
  327. #pragma parameter SetIntModemState(__D0)
  328. #endif
  329. extern pascal void SetIntModemState(short theState)
  330.  FOURWORDINLINE(0x4840, 0x303C, 0x000F, 0xA09E);
  331.  
  332. #if !GENERATINGCFM
  333. #pragma parameter __D0 MaximumProcessorSpeed
  334. #endif
  335. extern pascal short MaximumProcessorSpeed(void)
  336.  TWOWORDINLINE(0x7010, 0xA09E);
  337.  
  338. #if !GENERATINGCFM
  339. #pragma parameter __D0 CurrentProcessorSpeed
  340. #endif
  341. extern pascal short CurrentProcessorSpeed(void)
  342.  TWOWORDINLINE(0x7011, 0xA09E);
  343.  
  344. #if !GENERATINGCFM
  345. #pragma parameter __D0 FullProcessorSpeed
  346. #endif
  347. extern pascal Boolean FullProcessorSpeed(void)
  348.  TWOWORDINLINE(0x7012, 0xA09E);
  349.  
  350. #if !GENERATINGCFM
  351. #pragma parameter __D0 SetProcessorSpeed(__D0)
  352. #endif
  353. extern pascal Boolean SetProcessorSpeed(Boolean fullSpeed)
  354.  FOURWORDINLINE(0x4840, 0x303C, 0x0013, 0xA09E);
  355.  
  356. #if !GENERATINGCFM
  357. #pragma parameter __D0 GetSCSIDiskModeAddress
  358. #endif
  359. extern pascal short GetSCSIDiskModeAddress(void)
  360.  TWOWORDINLINE(0x7014, 0xA09E);
  361.  
  362. #if !GENERATINGCFM
  363. #pragma parameter SetSCSIDiskModeAddress(__D0)
  364. #endif
  365. extern pascal void SetSCSIDiskModeAddress(short scsiAddress)
  366.  FOURWORDINLINE(0x4840, 0x303C, 0x0015, 0xA09E);
  367.  
  368. #if !GENERATINGCFM
  369. #pragma parameter GetWakeupTimer(__A0)
  370. #endif
  371. extern pascal void GetWakeupTimer(WakeupTime *theTime)
  372.  TWOWORDINLINE(0x7016, 0xA09E);
  373.  
  374. #if !GENERATINGCFM
  375. #pragma parameter SetWakeupTimer(__A0)
  376. #endif
  377. extern pascal void SetWakeupTimer(WakeupTime *theTime)
  378.  TWOWORDINLINE(0x7017, 0xA09E);
  379.  
  380. #if !GENERATINGCFM
  381. #pragma parameter __D0 IsProcessorCyclingEnabled
  382. #endif
  383. extern pascal Boolean IsProcessorCyclingEnabled(void)
  384.  TWOWORDINLINE(0x7018, 0xA09E);
  385.  
  386. #if !GENERATINGCFM
  387. #pragma parameter EnableProcessorCycling(__D0)
  388. #endif
  389. extern pascal void EnableProcessorCycling(Boolean enable)
  390.  FOURWORDINLINE(0x4840, 0x303C, 0x0019, 0xA09E);
  391.  
  392. #if !GENERATINGCFM
  393. #pragma parameter __D0 BatteryCount
  394. #endif
  395. extern pascal short BatteryCount(void)
  396.  TWOWORDINLINE(0x701A, 0xA09E);
  397.  
  398. #if !GENERATINGCFM
  399. #pragma parameter __D0 GetBatteryVoltage(__D0)
  400. #endif
  401. extern pascal Fixed GetBatteryVoltage(short whichBattery)
  402.  FOURWORDINLINE(0x4840, 0x303C, 0x001B, 0xA09E);
  403.  
  404. #if !GENERATINGCFM
  405. #pragma parameter GetBatteryTimes(__D0, __A0)
  406. #endif
  407. extern pascal void GetBatteryTimes(short whichBattery, BatteryTimeRec *theTimes)
  408.  FOURWORDINLINE(0x4840, 0x303C, 0x001C, 0xA09E);
  409.  
  410. #if !GENERATINGCFM
  411. #pragma parameter __D0 GetDimmingTimeout
  412. #endif
  413. extern pascal UInt8 GetDimmingTimeout(void)
  414.  TWOWORDINLINE(0x701D, 0xA09E);
  415.  
  416. #if !GENERATINGCFM
  417. #pragma parameter SetDimmingTimeout(__D0)
  418. #endif
  419. extern pascal void SetDimmingTimeout(UInt8 timeout)
  420.  FOURWORDINLINE(0x4840, 0x303C, 0x001E, 0xA09E);
  421.  
  422. #if !GENERATINGCFM
  423. #pragma parameter DimmingControl(__D0)
  424. #endif
  425. extern pascal void DimmingControl(Boolean enableSleep)
  426.  FOURWORDINLINE(0x4840, 0x303C, 0x001F, 0xA09E);
  427.  
  428. #if !GENERATINGCFM
  429. #pragma parameter __D0 IsDimmingControlDisabled
  430. #endif
  431. extern pascal Boolean IsDimmingControlDisabled(void)
  432.  TWOWORDINLINE(0x7020, 0xA09E);
  433.  
  434. #if !GENERATINGCFM
  435. #pragma parameter __D0 IsAutoSlpControlDisabled
  436. #endif
  437. extern pascal Boolean IsAutoSlpControlDisabled(void)
  438.  TWOWORDINLINE(0x7021, 0xA09E);
  439. enum {
  440.     uppHDSpindownProcInfo = kPascalStackBased
  441.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(HDQueueElement*))),
  442.     uppSleepQProcInfo = kRegisterBased
  443.          | RESULT_SIZE(SIZE_CODE(sizeof(long)))
  444.          | REGISTER_RESULT_LOCATION(kRegisterD0)
  445.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(long)))
  446.          | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(SleepQRecPtr)))
  447. };
  448.  
  449. #if GENERATINGCFM
  450. #define NewHDSpindownProc(userRoutine)        \
  451.         (HDSpindownUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppHDSpindownProcInfo, GetCurrentArchitecture())
  452. #define NewSleepQProc(userRoutine)        \
  453.         (SleepQUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppSleepQProcInfo, GetCurrentArchitecture())
  454. #else
  455. #define NewHDSpindownProc(userRoutine)        \
  456.         ((HDSpindownUPP) (userRoutine))
  457. #define NewSleepQProc(userRoutine)        \
  458.         ((SleepQUPP) (userRoutine))
  459. #endif
  460.  
  461. #if GENERATINGCFM
  462. #define CallHDSpindownProc(userRoutine, theElement)        \
  463.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppHDSpindownProcInfo, (theElement))
  464. #define CallSleepQProc(userRoutine, message, qRecPtr)        \
  465.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSleepQProcInfo, (message), (qRecPtr))
  466. #else
  467. #define CallHDSpindownProc(userRoutine, theElement)        \
  468.         (*(userRoutine))((theElement))
  469. /* (*SleepQProcPtr) cannot be called from a high-level language without the Mixed Mode Manager */
  470. #endif
  471.  
  472.  
  473. #ifdef __CFM68K__
  474. #pragma lib_export off
  475. #endif
  476.  
  477. #if GENERATINGPOWERPC
  478. #pragma options align=reset
  479. #endif
  480.  
  481. #ifdef __cplusplus
  482. }
  483. #endif
  484.  
  485. #endif /* __POWER__ */
  486.